package entity;


import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.util.List;
import java.util.Objects;

//不返回将空字段null作为json返回
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Building {
    private Integer id;
    private String name;

    /**
     * 在返回json数据时，用一对多的关系更加清晰明了，
     * 因此添加个教室的列表属性
     */
    private List<Classroom> classrooms;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Classroom> getClassrooms() {
        return classrooms;
    }

    public void setClassrooms(List<Classroom> classrooms) {
        this.classrooms = classrooms;
    }

    @Override
    public String toString() {
        return "Building{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", classrooms=" + classrooms +
                '}';
    }

    //重写equals和hashCode，使其两个对象只要id和name相等即认为其是同一对象，方便进行多对一与一对多的转换(使用hashset)
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Building building = (Building) o;
        return id == building.id &&
                Objects.equals(name, building.name);
    }

    @Override
    public int hashCode() {

        return Objects.hash(id, name);
    }
}
